package com.lagou;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

public class ProducerMain {

    public static void main(String[] args) throws Exception {
        /**
         * 获取环境变量与启动参数
         */
        System.out.println(System.getenv("JAVA_HOME"));
//        System.out.println(System.getProperty("rocketmq.namesrv.addr"));
        System.out.println(System.getProperty("name"));
        DefaultMQProducer producer = new DefaultMQProducer("MyProduceGroup");
        /**
         * 不对nameserver硬编码，依次从启动参数，环境变量，特定服务器中获取（优先级由高到底）
         */
        producer.start();
        Message message = new Message("topic_1", "Hello Nameserver!".getBytes());
        SendResult result = producer.send(message);
        System.out.println("msgId:" + result.getMsgId() + ",status:" + result.getSendStatus());
        producer.shutdown();
    }

}
